<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>
<script type="text/javascript">
    var wins4ddTreeGrid = $.messager.progress({
        title:'提示',
        msg:'正在加载案件,请等待'
    });
		var treegrid = $("#dd_treegrid");
    
        function collapseDdAll(){
            $('#dd_treegrid').treegrid('collapseAll');
        }
        function expandDdAll(){
            $('#dd_treegrid').treegrid('expandAll');
        }
        
        function addDdFun() {
        	var dynamic_add_dialog  = $("<div/>").dialog({
			    title: '数据字典添加',
			    width: 800,
			    height: 350,
			    closed: false,
			    cache: false,
			    href: '${ctx}/dd/addTo',
			    modal: true,
			    buttons:[{
					text : '添加',
					iconCls: 'icon-add',
					handler : function() {
						$.serializeObject($('#ddadd_Form'));
						$('#ddadd_Form').form('submit',{
							url:'${ctx}/dd/save',
							onSubmit:function(){
							},
							success:function(data){
								var obj = $.parseJSON(data);
								if(obj.success){
									dynamic_add_dialog.dialog('close');
									treegrid.treegrid('reload');
								}
								$.messager.show({
									title:'提示',
									msg:obj.msg
								});
							}
						});
					}
				} ],
				onClose:function(){
					$(this).dialog('destroy');
				}
			});
    	}
        
        function editDd(){
    		var node = treegrid.treegrid('getSelected');
    		if(node!=null){
    		var ids = "";
    			var dynamic_edit_dialog  = $("<div/>").dialog({
    			    title: '数据字典编辑',
    			    width: 800,
    			    height: 350,
    			    closed: false,
    			    cache: false,
    			    href: '${ctx}/dd/editTo.do',
    			    modal: true,
    			    buttons:[{
    					text : '编辑',
    					iconCls: 'icon-add',
    					handler : function() {
    						$.serializeObject($('#ddEdit_edit_form'));
    						$('#ddEdit_edit_form').form('submit',{
    							url:'${ctx}/dd/edit',
    							onSubmit:function(){
    							},
    							success:function(data){
    								var obj = $.parseJSON(data);
    								if(obj.success){
    									dynamic_edit_dialog.dialog('close');
    									treegrid.treegrid('reload');
    									//treegrid.treegrid('append',{
    										//parent: node.id,  // the node has a 'id' value that defined through 'idField' property
    										//data: node
    									//});
    								}
    								$.messager.show({
    									title:'提示',
    									msg:obj.msg
    								});
    							}
    						});
    					}
    				} ],
    				onClose:function(){
    					$(this).dialog('destroy');
    				},
    				onLoad:function(){
    					$("#ddEdit_edit_form").form('load',node);
    				}
    			    
    			});
    		}else{
    			$.messager.alert('提示','请选择一条要编辑的记录！','info');
    		}
    	}

    	function removeDd() {
    		var treegrid = $("#dd_treegrid");
    		var node = treegrid.treegrid('getSelected');
    		if(node!=null){
    			$.messager.confirm('确认','确认要要删除吗？',function(r){
    			    if (r){
    					$.ajax({
    						url:'${ctx}/dd/del',
    						data:{
    							ids:node.id
    						},
    						dataType:'json',
    						success:function(data){
    							treegrid.treegrid('reload');
    							treegrid.treegrid('unselectAll');//使全部的行形成未選中狀態
    							$.messager.show({
    								title:'提示',
    								msg:data.msg
    							});
    						}
    					});
    			    }
    			});
    		}else{
    			$.messager.alert('提示','请选择一行来做删除操作！','info');
    		}
    	}
    </script>


    <table id="dd_treegrid" class="easyui-treegrid"  title="数据字典列表" 
            data-options="
            	border:false,
            	fit:true,
                iconCls: 'icon-ok',
                collapsible: true,
                fitColumns: true,
                url: '${ctx}/dd/treegrid.do',
                method: 'post',
                idField: 'id',
                parentField : 'pid',
                treeField: 'text',
                onLoadSuccess:function(){
                    $.messager.progress('close');
                },
                toolbar : [ {
					text : '添加',
					iconCls : 'icon-add',
					handler : function() {
						addDdFun();
					}
					}, '-', {
						text : '编辑',
						iconCls : 'icon-edit',
						handler : function() {
							editDd();
						}
					}, '-', {
						text : '删除',
						iconCls : 'icon-remove',
						handler : function() {
							removeDd();
						}
					} , '-', {
						text : '折叠',
						iconCls : 'resultset_previous',
						handler : function() {
							collapseDdAll();
						}
					} , '-', {
						text : '展开',
						iconCls : 'resultset_next',
						handler : function() {
							expandDdAll();
						}
					}]
            ">
        <thead>
            <tr>
                <th data-options="field:'text',width:60">数据字典名称</th>
                <th data-options="field:'value',width:60">数据字典值</th>
                <%--<th data-options="field:'isTitle',width:20">是否是标题</th>--%>
                <%--<th data-options="field:'isHot',width:20">是否是热门品牌</th>--%>
                <th data-options="field:'orderno',width:60">序号</th>
            </tr>
        </thead>
    </table>